{include file="my/header"}



<div class="container-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格数据查询块 -->
            <div class="table-query">
                <form class="layui-form layui-inline J-search-form" action="">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索ID：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="id" autocomplete="off" placeholder="请输入id">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">老师姓名:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="teachername" autocomplete="off" placeholder="请输入课老师姓名">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">考试任务:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="name" autocomplete="off" placeholder="请输入考试任务">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">老师角色:</label>
                        <div class="layui-input-block">
                            <select name="role" id="role">
                                <option value="">请选择</option>
                                <option value="0">监考</option>
                                <option value="1">巡考</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布时间:</label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input J-query-params J-date" name="create_time" placeholder="yyyy-MM-dd">
                        </div>
                    </div>

                </form>
                <button class="layui-btn J-search" data-type="reload">搜索</button>
                <button class="layui-btn J-reload">重置</button>
            </div>
            <!-- 表格 -->
            <table class="layui-hide" id="testTable" lay-filter="test"></table>
            <!-- 表格工具 -->
            <script type="text/html" id="toolbarDemo">
                 <!-- <div class="layui-btn-container">
                     <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
                     <button class="layui-btn layui-btn-sm" lay-event="batchdel">批量删除</button>
                 </div> -->
             </script>
            <script type="text/html" id="barDemo">
                 <a class="layui-btn layui-btn-xs" lay-event="add">添加监考老师</a>
                 <a class="layui-btn layui-btn-xs" lay-event="apply">查看监考申请</a>
                 <a class="layui-btn layui-btn-xs" lay-event="result">最终监考名单</a>

                 <!-- <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
             </script>
        </div>
        <!-- 弹出框模板 -->
        <div class="margin-top30 J-temple is-hidden">
            <form class="layui-form layui-fluid J-add-form" lay-filter="formTest">
                <input type="hidden" class="form-control" id="id" name="id" value="" placeholder="请输入内容">
                <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="985" placeholder="请输入内容">
                <input type="hidden" class="form-control" id="uid" name="uid" value="1" placeholder="请输入内容">
            </form>
        </div>
    </div>
    <script>
        $(function () {
            initClass('teacherlist')
            initTable();
            layuiDate(".J-date")

            // 编辑
            $(".J-edit").click(function () {
                let that = $(this);
                layerOpenInit('参考老师编辑', layerTemp, function (index) {
                    var data = $("form").serialize();
                    ajaxRequest("post", "{:url('test/teacheredit')}", data, function (data) {
                        data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                    })
                }, function () {

                    // 点击编辑获取当前编辑的数据
                    ajaxRequest("get", "{:url('test/teacheredit')}", {
                        id: that.attr('data-id')
                    }, function (res) {
                        $("#id").val(res.data.id);
                        $("#teacherid").val(res.data.teacherid);
                        $("#taskid").val(res.data.taskid);
                        $("#role").val(res.data.role);
                        $("#demo").val(res.data.demo);
                    })
                })
                return false;
            })

            // 新增
            $("#taskAdd").click(function () {
                layerOpenInit('添加参考老师', layerTemp, function (index) {
                    var formData = $("form").serialize();
                    formData += '&create_time=' + new Date().Format("yyyy-MM-dd hh:mm:ss");
                    
                    ajaxRequest("post", "{:url('test/teacheradd')}", formData, function (data) {
                        data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                    })
                })
                return false
            })

            // 删除
            $(".J-remove").click(function () {
                var data = {
                    id: $(this).attr('data-id')
                }
                layerConfirm("{:url('test/teachermove')}", data)
            });

            // layer模板
            var layerTemp = `

            `;
        })

        function initTable() {
            var table;
            // 请求路径
            var requireUrl = {
                add: "{:url('test/teacherlistadd')}",
                apply: "{:url('test/teachertestapp')}",
                remove: "{:url('test/teacherremove')}",
                list: "{:url('test/gettasklist')}",
                result: "{:url('test/teacherlistresult')}",

            }

            layui.use('table', function () {
                table = layui.table;
                table.render({
                    elem: '#testTable'
                    , url: requireUrl.list
                    , toolbar: '#toolbarDemo'
                    , title: '老师列表'
                    , totalRow: false
                    , cols: [[
                        { type: 'checkbox', fixed: 'left' }
                        , { field: 'id', title: '序号', }
                        , { field: 'name', title: '考试任务', }
                        , { field: 'term', title: '学期', }
                        , { field: 'create_time', title: '发布时间', }
                        , { fixed: 'right', title: '操作', toolbar: '#barDemo', minWidth: 350 }
                    ]]
                    , id: 'testReload'
                    , page: true
                    , parseData: function (res) {
                        return {
                            "code": 0,
                            "msg": "",
                            "count": res.length,
                            "data": res
                        };
                    }
                });

                //工具栏事件
                table.on('toolbar(test)', function (obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    var data = obj.data;
                    console.log(data.id)

                    switch (obj.event) {
                        case 'add':
                            tableAdd({
                                addUrl: requireUrl.add,
                                layerTemp: $('.J-temple'),
                                title: '添加参考老师'
                            });
                            break;
                        case 'batchdel':
                            tableBatchDel(checkStatus, requireUrl.remove);
                            break;
                    };
                });

                //监听行工具事件
                table.on('tool(test)', function (obj) {
                    var data = obj.data;

                    switch (obj.event) {
                        case 'add':
                            openFrame(requireUrl.add + '?taskid=' + data.id, '添加监考老师', ['1000px', '665px'])
                            break;
                        case 'result':
                            openFrame(requireUrl.result + '?taskid=' + data.id, '最终监考老师名单', ['1000px', '665px'])
                            break;
                        case 'apply':
                            openFrame(requireUrl.apply + '?taskid=' + data.id, '监考老师申请', ['1000px', '665px'])
                            break;
                    };
                });
            })

            // 搜索重置操作
            var active = {
                reload: function () {
                    var queryParams = serializeObject($(".J-search-form"));
                    console.log(queryParams);
                    //执行重载
                    table.reload('testReload', {
                        page: {
                            curr: 1 //重新从第 1 页开始
                        }
                        , where: queryParams
                    }, 'data');
                }
            };
            $('.J-search').on('click', function () {
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });
            $('.J-reload').on('click', function () {
                $('.J-query-params').val('');
                form.render('select');
                active.reload ? active.reload.call(this) : '';
            });

        }

    </script>

    {include file="my/footer"}